# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/26 15:34 
@Author  : ZhangShenao 
@File    : random_char.py 
@Desc    : 随机字符
"""
import random


class RandomCharacter:
    """
    随机字符类
    """

    def __init__(self):
        """
        构造函数
        初始化大写字母、小写字母、数字和特殊字符表
        """
        self.__all_upper_case = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
        self.__all_lower_case = 'abcdefghijklmnopqrstuvwxyz'
        self.__all_digit = '0123456789'
        self.__all_special_char = '!@#$%^&*()_+-=[]{}|;:,.<>/?'

    def random_char(self, char_table) -> str:
        """
        从指定的字符表中随机获取一个字符
        :param char_table: 字符表
        :return: 随机字符
        """
        length = len(char_table)
        index = random.randint(0, length - 1)
        return char_table[index]

    def random_upper_case(self) -> str:
        """随机生成一个大写字母"""
        return self.random_char(self.__all_upper_case)

    def random_lower_case(self) -> str:
        """随机生成一个小写字母"""
        return self.random_char(self.__all_lower_case)

    def random_digit(self) -> str:
        """随机生成一个数字"""
        return self.random_char(self.__all_digit)

    def random_special_char(self) -> str:
        """随机生成一个特殊字符"""
        return self.random_char(self.__all_special_char)

    def random_any(self) -> str:
        """随机生成一个任意字符"""
        return self.random_char(
            self.__all_upper_case + self.__all_lower_case + self.__all_digit + self.__all_special_char)
